﻿@{
    CurrentUser user = ViewBag.CurrentUser;
    int tableId = ViewBag.TableId;
    string table = ViewBag.Table;
    string action = ViewContext.RouteData.Values["action"].ToString();
    IEnumerable<dynamic> fieldData = Html.GetFieldList((string)ViewBag.Table, action, user, PageAdmin.Common.FromEnum.Member);
    dynamic permissions = ViewBag.Permissions;
    int addDefaultState = permissions.AddDefaultState;
    int editDefaultState = permissions.EditDefaultState;
    string guid = Html.Guid();
}
<script src="~/Incs/UEditor/ueditor.config.js" type="text/javascript"></script>
<script src="~/Incs/UEditor/ueditor.all.min.js" type="text/javascript"></script>
<div class="main">
    <form method="post" id="_form" class=" form-group-sm form ui-validForm" data-validate-params="beforeSubmit:'BeforeSubmit'" data-source="@Model">
        <div class="form-group" id="_ColumnIdBox">
            <label class="control-label">所属栏目*</label>
            <div class="controls form-inline">
                <select class="form-control" style="width:auto;" name="ColumnId" id="ColumnId" data-validate="dataType:'*',nullMsg:'请选择栏目!',errorMsg:'请选择栏目'" data-custom-params="valueField:'Id',textField:'Name',isTree:true,linkage:true" data-source="@Html.GetColumnListJsonByUser(tableId,user,PageAdmin.Common.FromEnum.Member)">
                    <option value="">请选择栏目...</option>
                </select>
                <span class="help-block"></span>
            </div>
            <script type="text/javascript">
                $("#ColumnId").SelectBind({ dataSourceFrom: "attr" }); //绑定栏目数据
            </script>
        </div>
        @{
            string beforeSubmitJs = "";
            var data = new ViewDataDictionary();
            data.Add("from", "member");
            data.Add("guid", guid);
            data.Add("currentUser", user);
            data.Add("i", 0); ;
            int i = 0;
            if (fieldData != null)
            {
                foreach (var row in fieldData)
                {
                    data["i"] = i;
                    beforeSubmitJs += row.BeforeSubmitJs;
                    Html.RenderPartial("~/Areas/E/Views/CustomForm/FormPartial.cshtml", (object)row, data);
                    i++;
                }
            }

        }
        <script type="text/javascript">
                function BeforeSubmit() {
                     @Html.Raw(beforeSubmitJs)
                    return true;
                }
        </script>

        @if (permissions.CanSetGoodProperty == 1 || permissions.CanSetHotProperty == 1 || permissions.CanSetTopProperty == 1)
        {
            <div class="form-group">
                <label class="control-label">信息属性</label>
                <div class="controls form-inline">
                    @if (permissions.CanSetGoodProperty == 1)
                    {
                        <select name="IsGood" id="IsGood" class="form-control" style="width:auto">
                            <option value="0">推荐属性</option>
                            <option value="1">1级推荐</option>
                            <option value="2">2级推荐</option>
                            <option value="3">3级推荐</option>
                            <option value="4">4级推荐</option>
                            <option value="5">5级推荐</option>
                            <option value="6">6级推荐</option>
                            <option value="7">7级推荐</option>
                            <option value="8">8级推荐</option>
                            <option value="9">9级推荐</option>
                            <option value="10">10级推荐</option>
                        </select>
                    }
                    @if (permissions.CanSetHotProperty == 1)
                    {
                        <select name="IsHot" id="IsHot" class="form-control" style="width:auto">
                            <option value="0">热门属性</option>
                            <option value="1">1级热门</option>
                            <option value="2">2级热门</option>
                            <option value="3">3级热门</option>
                            <option value="4">4级热门</option>
                            <option value="5">5级热门</option>
                            <option value="6">6级热门</option>
                            <option value="7">7级热门</option>
                            <option value="8">8级热门</option>
                            <option value="9">9级热门</option>
                            <option value="10">10级热门</option>
                        </select>
                    }
                    @if (permissions.CanSetTopProperty == 1)
                    {
                        <select name="IsTop" id="IsTop" class="form-control" style="width:auto">
                            <option value="0">置顶属性</option>
                            <option value="1">1级置顶</option>
                            <option value="2">2级置顶</option>
                            <option value="3">3级置顶</option>
                            <option value="4">4级置顶</option>
                            <option value="5">5级置顶</option>
                            <option value="6">6级置顶</option>
                            <option value="7">7级置顶</option>
                            <option value="8">8级置顶</option>
                            <option value="9">9级置顶</option>
                            <option value="10">10级置顶</option>
                        </select>
                    }
                    <span class="help-block">属性可用于前台数据筛选和组合，字段名分别为：isGood，isHot，isTop，都是数值类型</span>
                </div>
            </div>
        }

        @if (permissions.CanResubmitCheck == 1)
        {
            <div class="form-group resubmit-check-box hidden">
                <label class="control-label">重新提交审核</label>
                <div class="controls">
                    <span class="checkbox-inline"><input type="checkbox" id="_ResubmitCheck" name="_ResubmitCheck" value="1" />提交重新审核</span>
                    <span class="help-block">退回的信息勾选后重新提交可以再次进行审核</span>
                </div>
            </div>

        }

        <div class="form-group postarea">
            <div class="controls form-inline">
                <input type="hidden" name="Guid" id="Guid" value="@guid" />
                <input type="hidden" name="Id" id="Id" value="@ViewBag.DetailId" />
                <input type="hidden" name="State" id="State" value="0" />
                <button type="button" class="btn btn-sm  btn-primary ui-pagePost" data-custom-params="url:'@Url.ActionUrl()',callBack:'CallBack'">提交</button>
                <button type="button" class="btn btn-sm btn-default ui-closeDialog">关闭</button>
            </div>
        </div>
    </form>
</div>
<script src="~/Areas/Member/Js/infoData.js"></script>
<script type="text/javascript">
                var $state = $("#State");
                var $resubmitCheck = $("#_ResubmitCheck");
                var $reCheckBox = $(".resubmit-check-box");
                var id = Request("id");
                var currentState;
                if (id != "") {
                    $("#_form").FormBind({ dataSourceFrom: "attr" });
                    currentState = $state.val();
                    if (currentState == "1") {
                        $state.val(@editDefaultState);
                    }
                    else if (currentState == "-1") {
                        $reCheckBox.removeClass("hidden");;
                    }
                }
                else {
                    $state.val(@addDefaultState);
                    var columnId = GetLocalStorage("columnId");
                    if (columnId != "") {
                        $("#_ColumnIdBox").FormBind({}, { "ColumnId": columnId });
                    }
                }
                $resubmitCheck.click(function () {
                    var $this = $(this);
                    if ($this.prop("checked"))
                    {
                        $state.val(0);
                    }
                    else
                    {
                        $state.val(currentState);
                    }
                });


                function CallBack() {
                    var $columnId = $("#ColumnId");
                    var columnId = $columnId.val();
                    SetLocalStorage("columnId", columnId);
                    PostRefreshBack();
                }
</script>
